package JFrame.User;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import JFrame.Tools;

public class UserJFrame extends JFrame implements ActionListener {
    Timer timer = new Timer(200, this);
    String curUserId;
    public UserJFrame(String UserId) {
        curUserId=UserId;
        initializing();
    }
    public void initializing(){
        timer.start();

        JPanel panel=new JPanel();
        panel.setLayout(new GridLayout(4,1,10,10));
        panel.setBorder(new EmptyBorder(200, 20, 20, 20));
        add(panel);
        panel.setBackground(new Color(255, 255, 255));
        panel.setSize(400,172);
        JLabel Id =new JLabel("当前你的用户账号是:"+curUserId,SwingConstants.CENTER);

        JButton Change_Address =new JButton("修改个人信息");
        JButton Enquiry_Express =new JButton("查询个人快件");
        Change_Address.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                 new ChangeUserInformation(curUserId);
            }
        });
        Enquiry_Express.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new EnquiryMail(curUserId);
            }
        });

        this.setSize(400,550);
        setTitle("快递派送系统——用户");
        setResizable(false);
        setLocationRelativeTo(getOwner());
        Tools.setFonts(20,1,Id,Change_Address,Enquiry_Express);
        Tools.addComponents(panel,Id,Change_Address,Enquiry_Express);
        setVisible(true);
    }
    public void myPaint() {
        Graphics g = this.getGraphics();
        g.setColor(Color.black);
        g.fillRect(25,20,350,172);
        g.setColor(Color.yellow);
        for (int i=0;i<70;i++){
            int a=(int)(Math.random()*850);
            int b=(int)(Math.random()*172);
            g.drawString(".",a,b);
        }

    }
    @Override
    public void actionPerformed(ActionEvent e) {
            myPaint();
    }
}
